<?php
namespace Admin\Controller;
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * 连锁店控制器
 * @author caomenglong
 */
class SpShopController extends AdminController {
    
    //基础设置_门店列表
    public function shoplist(){
        $name = I('name');
        $map['status']  =   1;
        $map['name'] = array('like', '%' . (string) $name . '%');
        $list = $this->lists('sp_shops', $map,'creareat asc');
        int_to_string($list);
        $this->assign('_list', $list);
        $this->meta_title = '数据列表';
        $this->display();
    }
    
    //基础设置_门店添加
    public function shopadd($shopNum="",$name="",$address=""){
        if(IS_POST){
            $shop = array('shopNum' => $shopNum, 'name' => $name, 's_address' => $address, 'createby' => UID, 'creareat' => NOW_TIME);
            $id = M('sp_shops')->add($shop);
            if (!$id) {
                $this->error("添加失败！");
            } else {
                $this->success('添加成功！', U('shoplist'));
            }
        }else{
            $this->display();
        }
    }
    
    //基础设置_门店编辑
    public function shopedit($shopNum="",$name="",$address="") {
        $id = I('id');
        if (IS_POST) {
            $shop = array('shopNum' => $shopNum, 'name' => $name, 's_address' => $address);
            if (!M('sp_shops')->where(array('id' => $id))->save($shop)) {
                $this->error("修改失败！");
            } else {
                $this->success('修改成功！', U('shoplist'));
            }
        } else {
            $data = M('sp_shops')->where(array('id' => $id))->find();
            $this->data = $data;
            $this->display();
        }
    }
    
    //基础设置_门店删除
    public function del($id = 0) {
        if ($id) {
            $shop = M("sp_shops");
            
            $data = array('status'=>-1);
            $result = $shop-> where(array('id'=>$id))->setField($data);
            
            if($result){
                $this->success('删除成功！', U('shoplist'));
            }else{
                $this->error("删除失败！");
            }
        }
    }
    
    
    
}
